package thread;

/**
 * @author DBX
 * @effect  修改下面的代码,使得两个线程执行dosome方法时是同步的
 * @date 2021/09/01/19:54
 */
public class Test1 {
    public static void main(String[] args) {
        TestTest tt = new TestTest();
        Thread t1 = new Thread("t1"){
            @Override
            public void run() {
                tt.deSome();
            }
        };
        Thread t2 = new Thread("t2"){
            @Override
            public void run() {
                tt.deSome();
            }
        };
        t1.start();
        t2.start();
    }
}
class TestTest{
    public void deSome(){
        Thread t = Thread.currentThread();
        synchronized (this){
            System.out.println(t.getName()+"--->正在执行");
            try {
                t.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getName()+"--->执行完毕");
        }
    }
}